package com.wc.alorithm_luogu.P3799;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;

/**
 * @Author congege
 * @Description 妖梦拼木棒
 * https://www.luogu.com.cn/problem/P3799
 * @Date Created in 2023/9/23-20:16
 */
public class Main {
    public static void main(String[] args) {
        Input scan = new Input();

        int n = scan.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = scan.nextInt();
        }

        Arrays.sort(array);

        long ans = 0L;

        int max = array[n - 1];

        /**
         * 记录每一个数出现的次数
         */
        int[] number = new int[max + 1];

        for (int i : array) {
            number[i]++;
        }
        Main main = new Main();
        for (int i = max; i >= 1; i--) {
            /**
             * 2 + 1 + 1 模式
             */
            if (number[i] >= 2) {
                for (int j = i - 1; j >= 0; j--) {
                    /**
                     * 保证火柴数量有
                     */
                    if (number[j] != 0 && number[i - j] != 0) {
                        /**
                         * 保证只计算一次
                         */
                        if (i - j <= j) {
                            /**
                             * 当两个数是一样的
                             */
                            if (j * 2 == i) {
                                ans += main.arrange(2, number[j]) * main.arrange(2, number[i]);
                            } else {
                                /**
                                 * 算两次的时候小心是奇数
                                 */
                                ans += number[j] * number[i - j] * main.arrange(2, number[i]);
                            }
                        }
                    }
                }
            }
        }
        System.out.println(ans % 1000000007L);
    }

    /**
     * 排列组合
     *
     * @param up
     * @param down
     * @return
     */
    public long arrange(long up, long down) {
        if (up > down) {
            return 0;
        }
        long son = 1L;
        long mather = 1L;
        if (up > down / 2) {
            up = down - up;
        }
        long n = up;
        for (int i = 0; i < n; i++) {
            son *= down;
            mather *= up;
            down--;
            up--;
        }
        return son / mather;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
